package shuai.test;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import shuai.model.User;

public class Demo {
	Session session=null;
	
	public void init(){
		Configuration configuration=new AnnotationConfiguration().configure();
		SessionFactory factory=configuration.buildSessionFactory();
		session=factory.openSession();
	}
	
	
	public User userLogin(String username,String userpwd){
		String hql=" from 用户  where username=:name and userpwd=:pwd";
		Query query=session.createQuery(hql);
		query.setString("name", username);
		query.setString("pwd", userpwd);
		List<User> users=query.list();
		
		//User user=(User) query.list();
		//System.out.println("用户名："+user.getUsername()+",电话号码:"+user.getUserphone());
		if(users!=null){
			return users.get(0);
		}else{
			return null;
		}
	}
	
	
	public void des(){
		session.close();
	}
}
